🎖️GitЯра🎖️
Node / meshtastic / Meshtastic-Android / files / core / data / src / commonMain / kotlin / org / meshtastic / core / data / repository / MaintenanceUf2RepositoryImpl.kt
Displaying Raw • Download
core/data/src/commonMain/kotlin/org/meshtastic/core/data/repository/MaintenanceUf2RepositoryImpl.kt bd2863243bab6eb213401d949839a2bc74dde7e2 (bd286324) Text, 4.28 KB
T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.core.data.repository
Tff7b72import T7ee787co.touchlab.kermit.Logger
Tff7b72import T7ee787kotlinx.coroutines.sync.Mutex
Tff7b72import T7ee787kotlinx.coroutines.sync.withLock
Tff7b72import T7ee787kotlinx.serialization.json.Json
Tff7b72import T7ee787org.koin.core.annotation.Single
Tff7b72import T7ee787org.meshtastic.core.common.util.safeCatching
Tff7b72import T7ee787org.meshtastic.core.data.datasource.BundledAssetReader
Tff7b72import T7ee787org.meshtastic.core.data.datasource.MaintenanceUf2LocalDataSource
Tff7b72import T7ee787org.meshtastic.core.data.datasource.decode
Tff7b72import T7ee787org.meshtastic.core.database.entity.asEntity
Tff7b72import T7ee787org.meshtastic.core.database.entity.asExternalModel
Tff7b72import T7ee787org.meshtastic.core.model.MaintenanceUf2Manifest
Tff7b72import T7ee787org.meshtastic.core.network.MaintenanceUf2RemoteDataSource
Tff7b72import T7ee787org.meshtastic.core.repository.MaintenanceUf2Repository
T8b949e/**
* Caches the maintenance-UF2 manifest from the Meshtastic API (`/resource/maintenanceUf2`), seeded from the bundled
* `maintenance_uf2.json` snapshot so it is never empty offline — mirrors [BootloaderOtaQuirksRepositoryImpl]'s
* seed-then-refresh shape exactly, including its "reconcile carries no TTL of its own" contract:
* [DeviceHardwareRepositoryImpl]'s refresher calls this on the same cadence as its catalog refresh.
*/
Tf0883e@Single
Tff7b72class T56d364MaintenanceUf2RepositoryImplTb4b4b4(
Tff7b72private Tff7b72val Te6edf3remoteDataSourceTb4b4b4: Te6edf3MaintenanceUf2RemoteDataSourceTb4b4b4,
Tff7b72private Tff7b72val Te6edf3localDataSourceTb4b4b4: Te6edf3MaintenanceUf2LocalDataSourceTb4b4b4,
Tff7b72private Tff7b72val Te6edf3assetReaderTb4b4b4: Te6edf3BundledAssetReaderTb4b4b4,
Tff7b72private Tff7b72val Te6edf3jsonTb4b4b4: Te6edf3JsonTb4b4b4,
Tb4b4b4) Tb4b4b4: Te6edf3MaintenanceUf2Repository Tb4b4b4{
T8b949e/** Serializes seeding and network writes so concurrent callers don't duplicate/interleave them. */
Tff7b72private Tff7b72val Te6edf3writeMutex Tff7b72= Te6edf3MutexTb4b4b4(Tb4b4b4)
Tff7b72override Tff7b72suspend Tff7b72fun Td2a8ffgetSnapshotTb4b4b4(Tb4b4b4)Tb4b4b4: Te6edf3MaintenanceUf2Manifest Tb4b4b4{
Te6edf3ensureSeededTb4b4b4(Tb4b4b4)
Tff7b72return Te6edf3localDataSourceTb4b4b4.Te6edf3getTb4b4b4(Tb4b4b4)Tff7b72?.Te6edf3asExternalModelTb4b4b4(Tb4b4b4) Tff7b72?: Te6edf3MaintenanceUf2ManifestTb4b4b4(Tb4b4b4)
Tb4b4b4}
Tff7b72override Tff7b72suspend Tff7b72fun Td2a8ffreconcileTb4b4b4(Tb4b4b4) Tb4b4b4{
Te6edf3safeCatching Tb4b4b4{ Te6edf3remoteDataSourceTb4b4b4.Te6edf3getManifestTb4b4b4(Tb4b4b4) Tb4b4b4}
Tb4b4b4.Te6edf3onSuccess Tb4b4b4{ Te6edf3manifest Tff7b72-Tff7b72> Te6edf3writeMutexTb4b4b4.Te6edf3withLock Tb4b4b4{ Te6edf3storeTb4b4b4(Te6edf3manifestTb4b4b4) Tb4b4b4} Tb4b4b4}
Tb4b4b4.Te6edf3onFailure Tb4b4b4{ Te6edf3e Tff7b72-Tff7b72> Te6edf3LoggerTb4b4b4.Te6edf3wTb4b4b4(Te6edf3eTb4b4b4) Tb4b4b4{ Ta5d6ff"Ta5d6ffMaintenanceUf2Repository: network refresh failedTa5d6ff" Tb4b4b4} Tb4b4b4}
Tb4b4b4}
T8b949e/** Seeds the cache from the bundled snapshot if empty (fresh install, data clear). */
Tff7b72private Tff7b72suspend Tff7b72fun Td2a8ffensureSeededTb4b4b4(Tb4b4b4) Tb4b4b4{
Tff7b72if Tb4b4b4(Te6edf3localDataSourceTb4b4b4.Te6edf3countTb4b4b4(Tb4b4b4) Tff7b72> T79c0ff0Tb4b4b4) Tff7b72return
Te6edf3writeMutexTb4b4b4.Te6edf3withLock Tb4b4b4{
Tff7b72if Tb4b4b4(Te6edf3localDataSourceTb4b4b4.Te6edf3countTb4b4b4(Tb4b4b4) Tff7b72=Tff7b72= T79c0ff0Tb4b4b4) Tb4b4b4{
Te6edf3safeCatching Tb4b4b4{
Tff7b72val Te6edf3asset Tff7b72= Te6edf3assetReaderTb4b4b4.Te6edf3decodeTff7b72<Te6edf3MaintenanceUf2ManifestTff7b72>Tb4b4b4(Ta5d6ff"Ta5d6ffmaintenance_uf2.jsonTa5d6ff"Tb4b4b4, Te6edf3jsonTb4b4b4)
Te6edf3assetTff7b72?.Te6edf3let Tb4b4b4{ Te6edf3storeTb4b4b4(Tffa657itTb4b4b4) Tb4b4b4}
Tb4b4b4}
Tb4b4b4.Te6edf3onFailure Tb4b4b4{ Te6edf3e Tff7b72-Tff7b72> Te6edf3LoggerTb4b4b4.Te6edf3wTb4b4b4(Te6edf3eTb4b4b4) Tb4b4b4{ Ta5d6ff"Ta5d6ffMaintenanceUf2Repository: failed to seed from bundled JSONTa5d6ff" Tb4b4b4} Tb4b4b4}
Tb4b4b4}
Tb4b4b4}
Tb4b4b4}
T8b949e/**
* Not locked itself — every caller already holds [writeMutex] for the duration of a write.
*
* A manifest with neither erase images nor an OTAFIX board map is ignored rather than stored, so a fully empty
* response can never wipe an existing seed/cache back to nothing. A *partial* response still replaces the cached
* manifest wholesale — the server is authoritative for which images exist, so a dropped section means that section
* was withdrawn, and the resolvers fail closed on the sections it no longer carries.
*/
Tff7b72private Tff7b72suspend Tff7b72fun Td2a8ffstoreTb4b4b4(Te6edf3manifestTb4b4b4: Te6edf3MaintenanceUf2ManifestTb4b4b4) Tb4b4b4{
Tff7b72if Tb4b4b4(Te6edf3manifestTb4b4b4.Te6edf3erase Tff7b72=Tff7b72= Tff7b72null Tff7b72&Tff7b72& Te6edf3manifestTb4b4b4.Te6edf3otafixByBoardIdTb4b4b4.Te6edf3isEmptyTb4b4b4(Tb4b4b4)Tb4b4b4) Tb4b4b4{
Te6edf3LoggerTb4b4b4.Te6edf3w Tb4b4b4{ Ta5d6ff"Ta5d6ffMaintenanceUf2Repository: empty response; leaving cache untouchedTa5d6ff" Tb4b4b4}
Tff7b72return
Tb4b4b4}
Te6edf3localDataSourceTb4b4b4.Te6edf3upsertTb4b4b4(Te6edf3manifestTb4b4b4.Te6edf3asEntityTb4b4b4(Tb4b4b4)Tb4b4b4)
Tb4b4b4}
Tb4b4b4}
Served by rngit 1.5.0 - Generated in 0.11s